package com.example.bookmanagement.common;

import lombok.Data;

@Data
public class AjaxResponse<T> {

    private int code;
    private String msg;
    private T data;

    public static <T> AjaxResponse<T> success(T data) {
        AjaxResponse<T> response = new AjaxResponse<>();
        response.setCode(200);
        response.setMsg("成功");
        response.setData(data);
        return response;
    }

    public static <T> AjaxResponse<T> error(String msg) {
        AjaxResponse<T> response = new AjaxResponse<>();
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }
    public static <T> AjaxResponse<T> error(int code, String msg) {
        AjaxResponse<T> response = new AjaxResponse<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
}    